<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <title>三国武将名录</title>
    <style>
        /* 基础样式重置 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Microsoft YaHei', '微软雅黑', sans-serif;
        }

        /* 全局样式 */
        body {
            background: linear-gradient(rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.7)),
            url('${pageContext.request.contextPath}/i.png') no-repeat center center fixed;
            background-size: cover;
            color: #f0f0f0;
            padding: 20px;
            min-height: 100vh;
        }

        /* 主容器 */
        .container {
            max-width: 1200px;
            margin: 20px auto;
            background: rgba(30, 30, 30, 0.3);
            border-radius: 12px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
            border: 1px solid rgba(212, 167, 106, 0.3);
            backdrop-filter: blur(8px);
            padding: 30px;
        }

        /* 标题区域 */
        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 25px;
            padding-bottom: 15px;
            border-bottom: 1px solid rgba(212, 167, 106, 0.3);
        }

        h1 {
            color: #d4a76a;
            font-size: 2.2rem;
            letter-spacing: 2px;
            text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.8);
        }

        /* 表格样式 */
        table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 25px;
            background: rgba(40, 40, 40, 0.7);
            border-radius: 8px;
            overflow: hidden;
        }

        th, td {
            padding: 15px;
            text-align: center;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }

        th {
            background: rgba(212, 167, 106, 0.2);
            color: #d4a76a;
            font-weight: bold;
            cursor: pointer;
        }

        th:hover {
            background: rgba(212, 167, 106, 0.3);
        }

        tr:hover {
            background: rgba(255, 255, 255, 0.05);
        }

        /* 按钮样式 */
        .btn {
            padding: 8px 16px;
            border-radius: 6px;
            border: none;
            cursor: pointer;
            font-weight: bold;
            transition: all 0.3s;
            text-decoration: none;
            display: inline-block;
            margin: 0 5px;
            font-size: 0.9rem;
        }

        .btn-add {
            background: linear-gradient(135deg, #d4a76a, #b88746);
            color: #1a1a1a;
        }

        .btn-add:hover {
            background: linear-gradient(135deg, #b88746, #d4a76a);
        }

        .btn-edit {
            background: rgba(75, 192, 192, 0.2);
            color: #4bc0c0;
            border: 1px solid #4bc0c0;
        }

        .btn-edit:hover {
            background: rgba(75, 192, 192, 0.4);
        }

        .btn-delete {
            background: rgba(255, 99, 132, 0.2);
            color: #ff6384;
            border: 1px solid #ff6384;
        }

        .btn-delete:hover {
            background: rgba(255, 99, 132, 0.4);
        }

        /* 分页样式 - 保持原有功能结构不变 */
        .pagination {
            display: flex;
            justify-content: center;
            margin-top: 20px;
            padding: 10px;
            background-color: rgba(40, 40, 40, 0.7);
            border-radius: 5px;
            flex-wrap: wrap;
            gap: 5px;
        }

        .pagination a {
            padding: 8px 16px;
            text-decoration: none;
            border: 1px solid rgba(255, 255, 255, 0.2);
            color: #f0f0f0;
            border-radius: 4px;
        }

        .pagination a.active {
            background: rgba(212, 167, 106, 0.4);
            color: #d4a76a;
            font-weight: bold;
            border-color: #d4a76a;
        }

        .pagination a:hover:not(.active) {
            background: rgba(255, 255, 255, 0.1);
        }

        .pagination a.disabled {
            pointer-events: none;
            opacity: 0.5;
        }

        .pagination-controls {
            display: flex;
            align-items: center;
            gap: 10px;
            margin: 10px 0;
            color: #f0f0f0;
        }

        .pagination-controls input[type="number"] {
            width: 60px;
            padding: 5px;
            background: rgba(255, 255, 255, 0.1);
            border: 1px solid rgba(255, 255, 255, 0.2);
            border-radius: 4px;
            color: #f0f0f0;
        }

        .pagination-controls button {
            padding: 5px 10px;
            background: rgba(212, 167, 106, 0.4);
            color: #f0f0f0;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }

        .pagination-controls button:hover {
            background: rgba(212, 167, 106, 0.6);
        }
    </style>
</head>
<body>
<div class="container">
    <div class="header">
        <h1>三国武将名录</h1>
        <a href="general?action=add" class="btn btn-add">添加武将</a>
    </div>

    <table>
        <thead>
        <tr>
            <th onclick="sort('id')">ID</th>
            <th onclick="sort('name')">姓名</th>
            <th onclick="sort('strategy')">谋略</th>
            <th onclick="sort('force')">武力</th>
            <th onclick="sort('agility')">敏捷</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${generals}" var="general">
            <tr>
                <td>${general.id}</td>
                <td>${general.name}</td>
                <td>${general.strategy}</td>
                <td>${general.force}</td>
                <td>${general.agility}</td>
                <td>
                    <a href="general?action=edit&id=${general.id}" class="btn btn-edit">编辑</a>
                    <a href="general?action=delete&id=${general.id}" class="btn btn-delete" onclick="return confirm('确定要删除这位武将吗？')">删除</a>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>

    <div class="pagination">
        <div class="pagination-controls">
            <span>每页显示：</span>
            <input type="number" id="pageSizeInput" min="1" max="100" value="${pageSize}" onchange="changePageSize(this.value)">
            <span>条</span>
            <span>跳转到：</span>
            <input type="number" id="pageInput" min="1" max="${totalPages}" value="${currentPage}">
            <button onclick="goToPage()">跳转</button>
        </div>

        <c:if test="${currentPage > 1}">
            <a href="general?page=${currentPage-1}&sort=${sortField}&pageSize=${pageSize}">&laquo; 上一页</a>
        </c:if>

        <c:forEach begin="1" end="${totalPages}" var="i">
            <c:choose>
                <c:when test="${i == currentPage}">
                    <a href="#" class="active">${i}</a>
                </c:when>
                <c:otherwise>
                    <a href="general?page=${i}&sort=${sortField}&pageSize=${pageSize}">${i}</a>
                </c:otherwise>
            </c:choose>
        </c:forEach>

        <c:if test="${currentPage < totalPages}">
            <a href="general?page=${currentPage+1}&sort=${sortField}&pageSize=${pageSize}">下一页 &raquo;</a>
        </c:if>
    </div>
</div>

<script>
    function sort(field) {
        window.location.href = 'general?sort=' + field + '&pageSize=${pageSize}';
    }

    function changePageSize(size) {
        window.location.href = 'general?page=1&sort=${sortField}&pageSize=' + size;
    }

    function goToPage() {
        const page = document.getElementById('pageInput').value;
        if (page >= 1 && page <= ${totalPages}) {
            window.location.href = 'general?page=' + page + '&sort=${sortField}&pageSize=${pageSize}';
        } else {
            alert('请输入有效的页码（1-${totalPages}）');
        }
    }
</script>
</body>
</html>